var onNfc = function(nfcEvent) {
    if ( nfcEvent && nfcEvent.tag && nfcEvent.tag.id ) {
        var tagId = nfc.bytesToHexString(nfcEvent.tag.id);
        
        var expeditionId = getExpeditionIdFromNfcId(tagId);

        if (!expeditionId) {
            alert('Ce tag NFC ne correspond pas à une expédition');
        }
        else {
            validateExpedition(expeditionId);
        }
    }
    else {
        console.log("NFC tag doesn't have an ID");
    }
};

document.addEventListener('deviceready', function() {
    nfc.addNdefListener(
        onNfc,
        function() { console.log('addNdefListener is ready'); },
        function() { console.log('An error occurs'); }
    );

    nfc.addTagDiscoveredListener(
        onNfc,
        function() { console.log('addTagDiscoveredListener is ready'); },
        function() { console.log('An error occurs'); }
    );
});